﻿using System;
using InteractiveFiction.Model;

namespace Interpreter
{
    public class PrintState
    {
        public string DescribeNode(StoryNode node)
        {
            return node.Name + @"

" + node.Description + @"

" + PrintItems(node);
        }

        string PrintItems(StoryNode node)
        {
            if (node.Items.Count <= 0)
                return "";
            else if (node.Items.Count == 1)
                return "Here there is " + Utils.Article(node.Items[0].Name, node.Items[0].DefiniteArticle, false) + ".";

            string s = "";
            for (int i = 0; i < node.Items.Count; i++)
            {
                if (i == node.Items.Count - 1)
                    s += " and ";
                s += Utils.Article(node.Items[i].Name, node.Items[0].DefiniteArticle, i == 0);
                if (i == node.Items.Count - 1)
                    s += ", ";
                else
                    s += " lie here.";
            }
            return s;
        }

        string PrintInventory(Character character, bool thePlayer)
        {
            if (character.Inventory.Count <= 0)
                return "";
            else if (character.Inventory.Count == 1)
                return Utils.ConjugateHave(character, thePlayer) + Utils.Article(character.Inventory[0].Name, character.Inventory[0].DefiniteArticle, false) + ".";

            string s = Utils.ConjugateHave(character, thePlayer);
            for (int i = 0; i < character.Inventory.Count; i++)
            {
                if (i == character.Inventory.Count - 1)
                    s += " and ";
                s += " " + Utils.Article(character.Inventory[i].Name, character.Inventory[0].DefiniteArticle, false);
                if (i == character.Inventory.Count - 1)
                    s += ", ";
                else
                    s += ".";
            }
            return s;
        }
    }
}
